package com.mcglib.ds
{
	import flash.utils.Dictionary;

	public class DicMap
	{
		
		private var dic:Dictionary;
		
		private var _size:int = 0;
		
		private var _weekReference:Boolean;
		
		public function DicMap()
		{
			dic = new Dictionary();
		}
		
		public function get size():int
		{
			return _size;
		}

		public function put(key:*,value:*):void{
			
			if(key==null || value==null)
				throw new Error("DicMap不支持null key或null value");
			
			if(dic[key]==null)
				_size++;
			
			dic[key] = value;
		}
		
		public function getValue(key:*):*{
			return dic[key];
		}
		
		public function deleteItem(key:*):*{
			var value:* = dic[key];
			
			if(value!=null)
				_size--;
			delete dic[key];
			
			return value;
		}
		
		public function clear():void{
			_size = 0;
			dic = new Dictionary();
		}
		
		public function searchFirstKey(value:*):*{
			for(var key:* in dic){
				if(dic[key]==value)
					return key;
			}
			
			return null;
		}
		
		public function containKey(key:*):Boolean{
			return dic[key]!=null;
		}
		
		public function containValue(value:*):Boolean{
			for each(var v:* in dic){
				if(v==value)
					return true;
			}
			
			return false;
		}
		
		public function keys():Array{
			var arr:Array = new Array;
			for(var key:* in dic){
				arr.push(key);
			}
			
			return arr;
		}
		
		public function values():Array{
			var arr:Array = new Array;
			for each(var v:* in dic){
				arr.push(v);
			}
			
			return arr;
		}
		
	}
}